<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/solvers/adadelta_solver.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">src/caffe/solvers</a> - adadelta_solver.cpp<span style="font-size: 80%;"> (source / <a href="adadelta_solver.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">27</td>
            <td class="headerCovTableEntryLo">7.4 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">8</td>
            <td class="headerCovTableEntryLo">25.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;vector&gt;</a>
<span class="lineNum">       2 </span>            : 
<span class="lineNum">       3 </span>            : #include &quot;caffe/sgd_solvers.hpp&quot;
<span class="lineNum">       4 </span>            : 
<span class="lineNum">       5 </span>            : namespace caffe {
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">       8 </span><span class="lineNoCov">          0 : void AdaDeltaSolver&lt;Dtype&gt;::AdaDeltaPreSolve() {</span>
<span class="lineNum">       9 </span>            :   // Add the extra history entries for AdaDelta after those from
<span class="lineNum">      10 </span>            :   // SGDSolver::PreSolve
<span class="lineNum">      11 </span>            :   const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; net_params = this-&gt;net_-&gt;learnable_params();
<span class="lineNum">      12 </span><span class="lineNoCov">          0 :   for (int i = 0; i &lt; net_params.size(); ++i) {</span>
<span class="lineNum">      13 </span><span class="lineNoCov">          0 :         const vector&lt;int&gt;&amp; shape = net_params[i]-&gt;shape();</span>
<span class="lineNum">      14 </span><span class="lineNoCov">          0 :         this-&gt;history_.push_back(</span>
<span class="lineNum">      15 </span>            :                 shared_ptr&lt;Blob&lt;Dtype&gt; &gt;(new Blob&lt;Dtype&gt;(shape)));
<span class="lineNum">      16 </span>            :   }
<span class="lineNum">      17 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      20 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      21 </span>            : void adadelta_update_gpu(int N, Dtype* g, Dtype* h, Dtype* h2, Dtype momentum,
<span class="lineNum">      22 </span>            :     Dtype delta, Dtype local_rate);
<span class="lineNum">      23 </span>            : #endif
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      26 </span><span class="lineNoCov">          0 : void AdaDeltaSolver&lt;Dtype&gt;::ComputeUpdateValue(int param_id, Dtype rate) {</span>
<span class="lineNum">      27 </span>            :   const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; net_params = this-&gt;net_-&gt;learnable_params();
<span class="lineNum">      28 </span>            :   const vector&lt;float&gt;&amp; net_params_lr = this-&gt;net_-&gt;params_lr();
<span class="lineNum">      29 </span><span class="lineNoCov">          0 :   Dtype delta = this-&gt;param_.delta();</span>
<span class="lineNum">      30 </span><span class="lineNoCov">          0 :   Dtype momentum = this-&gt;param_.momentum();</span>
<span class="lineNum">      31 </span><span class="lineNoCov">          0 :   Dtype local_rate = rate * net_params_lr[param_id];</span>
<span class="lineNum">      32 </span>            :   size_t update_history_offset = net_params.size();
<span class="lineNum">      33 </span><span class="lineNoCov">          0 :   switch (Caffe::mode()) {</span>
<span class="lineNum">      34 </span>            :   case Caffe::CPU: {
<span class="lineNum">      35 </span>            :     // compute square of gradient in update
<span class="lineNum">      36 </span><span class="lineNoCov">          0 :     caffe_powx(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      37 </span>            :         net_params[param_id]-&gt;cpu_diff(), Dtype(2),
<span class="lineNum">      38 </span>            :         this-&gt;update_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            :     // update history of gradients
<span class="lineNum">      41 </span><span class="lineNoCov">          0 :     caffe_cpu_axpby(net_params[param_id]-&gt;count(), Dtype(1) - momentum,</span>
<span class="lineNum">      42 </span>            :         this-&gt;update_[param_id]-&gt;cpu_data(), momentum,
<span class="lineNum">      43 </span>            :         this-&gt;history_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            :     // add delta to history to guard against dividing by zero later
<span class="lineNum">      46 </span><span class="lineNoCov">          0 :     caffe_set(net_params[param_id]-&gt;count(), delta,</span>
<span class="lineNum">      47 </span>            :         this-&gt;temp_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span><span class="lineNoCov">          0 :     caffe_add(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      50 </span>            :         this-&gt;temp_[param_id]-&gt;cpu_data(),
<span class="lineNum">      51 </span><span class="lineNoCov">          0 :         this-&gt;history_[update_history_offset + param_id]-&gt;cpu_data(),</span>
<span class="lineNum">      52 </span>            :         this-&gt;update_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span><span class="lineNoCov">          0 :     caffe_add(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      55 </span>            :         this-&gt;temp_[param_id]-&gt;cpu_data(),
<span class="lineNum">      56 </span>            :         this-&gt;history_[param_id]-&gt;cpu_data(),
<span class="lineNum">      57 </span>            :         this-&gt;temp_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      58 </span>            : 
<span class="lineNum">      59 </span>            :     // divide history of updates by history of gradients
<span class="lineNum">      60 </span><span class="lineNoCov">          0 :     caffe_div(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      61 </span>            :         this-&gt;update_[param_id]-&gt;cpu_data(),
<span class="lineNum">      62 </span>            :         this-&gt;temp_[param_id]-&gt;cpu_data(),
<span class="lineNum">      63 </span>            :         this-&gt;update_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span>            :     // jointly compute the RMS of both for update and gradient history
<span class="lineNum">      66 </span><span class="lineNoCov">          0 :     caffe_powx(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      67 </span>            :         this-&gt;update_[param_id]-&gt;cpu_data(), Dtype(0.5),
<span class="lineNum">      68 </span>            :         this-&gt;update_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      69 </span>            : 
<span class="lineNum">      70 </span>            :     // compute the update
<span class="lineNum">      71 </span><span class="lineNoCov">          0 :     caffe_mul(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      72 </span>            :         net_params[param_id]-&gt;cpu_diff(),
<span class="lineNum">      73 </span>            :         this-&gt;update_[param_id]-&gt;cpu_data(),
<span class="lineNum">      74 </span>            :         net_params[param_id]-&gt;mutable_cpu_diff());
<span class="lineNum">      75 </span>            : 
<span class="lineNum">      76 </span>            :     // compute square of update
<span class="lineNum">      77 </span><span class="lineNoCov">          0 :     caffe_powx(net_params[param_id]-&gt;count(),</span>
<span class="lineNum">      78 </span>            :         net_params[param_id]-&gt;cpu_diff(), Dtype(2),
<span class="lineNum">      79 </span>            :         this-&gt;update_[param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      80 </span>            : 
<span class="lineNum">      81 </span>            :     // update history of updates
<span class="lineNum">      82 </span><span class="lineNoCov">          0 :     caffe_cpu_axpby(net_params[param_id]-&gt;count(), Dtype(1) - momentum,</span>
<span class="lineNum">      83 </span>            :         this-&gt;update_[param_id]-&gt;cpu_data(), momentum,
<span class="lineNum">      84 </span>            :         this-&gt;history_[update_history_offset + param_id]-&gt;mutable_cpu_data());
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            :     // apply learning rate
<span class="lineNum">      87 </span><span class="lineNoCov">          0 :     caffe_cpu_scale(net_params[param_id]-&gt;count(), local_rate,</span>
<span class="lineNum">      88 </span>            :         net_params[param_id]-&gt;cpu_diff(),
<span class="lineNum">      89 </span>            :         net_params[param_id]-&gt;mutable_cpu_diff());
<span class="lineNum">      90 </span>            :     break;
<span class="lineNum">      91 </span>            :   }
<span class="lineNum">      92 </span>            :   case Caffe::GPU: {
<span class="lineNum">      93 </span>            : #ifndef CPU_ONLY
<span class="lineNum">      94 </span>            :     adadelta_update_gpu(net_params[param_id]-&gt;count(),
<span class="lineNum">      95 </span>            :         net_params[param_id]-&gt;mutable_gpu_diff(),
<span class="lineNum">      96 </span>            :         this-&gt;history_[param_id]-&gt;mutable_gpu_data(),
<span class="lineNum">      97 </span>            :         this-&gt;history_[update_history_offset + param_id]-&gt;mutable_gpu_data(),
<span class="lineNum">      98 </span>            :         momentum, delta, local_rate);
<span class="lineNum">      99 </span>            : #else
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :     NO_GPU;</span>
<span class="lineNum">     101 </span>            : #endif
<span class="lineNum">     102 </span>            :     break;
<span class="lineNum">     103 </span>            :   }
<span class="lineNum">     104 </span>            :   default:
<span class="lineNum">     105 </span><span class="lineNoCov">          0 :     LOG(FATAL) &lt;&lt; &quot;Unknown caffe mode: &quot; &lt;&lt; Caffe::mode();</span>
<span class="lineNum">     106 </span>            :   }
<span class="lineNum">     107 </span><span class="lineNoCov">          0 : }</span>
<a name="108"><span class="lineNum">     108 </span>            : </a>
<span class="lineNum">     109 </span>            : INSTANTIATE_CLASS(AdaDeltaSolver);
<a name="110"><span class="lineNum">     110 </span><span class="lineCov">          3 : REGISTER_SOLVER_CLASS(AdaDelta);</span></a>
<span class="lineNum">     111 </span>            : 
<span class="lineNum">     112 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
